/**
 * 签到表管理
 */
<template>
  <div class="courseBox">
    <div class="courseBoxTop">
      <div class="courseBoxTopSearch">
        <div class="courseName">
          <span>考试名称：</span>
          <el-input v-model="examPaper" placeholder="请输入考试名称" />
        </div>
        <div class="searchAndReset">
          <el-button class="searchBtn" @click="searchInput">
            <i class="el-icon-search"></i>
            <span>搜索</span>
          </el-button>
          <el-button class="resetBtn" @click="refreshInput">
            <i class="el-icon-refresh"></i>
            <span>重置</span>
          </el-button>
        </div>
      </div>
    </div>

    <!-- 管理列表 -->
    <div class="courseBoxBottom">
      <div class="bottomHeader">
        <el-button type="primary" @click="batchPrint">批量打印</el-button>
      </div>
      <!-- <div class="alert">
        <i class="el-icon-info" style="color: #339dff; margin-left: 10px"></i>
        <p style="display: inline-block">
          已选择<span style="color: #339dff"
            ><span v-if="length.length == 0">0</span>{{ length }}</span
          >项&nbsp;本次查询耗时:&nbsp;{{showTime}}毫秒&nbsp;
        </p>
      </div> -->
      <!-- 表格 -->
      <div class="bottomMian">
        <el-table
          ref="multipleTable"
          @select-all="itemHandleSelectionAll"
          @select="itemHandleSelectionChange"
          :data="tableData"
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" align="content"> </el-table-column>
          <el-table-column type="index" label="序号" align="content">
          </el-table-column>
          <el-table-column prop="examPaper" label="考试名称" align="content">
          </el-table-column>
          <el-table-column label="考试时间" align="content" prop="examTime">
          </el-table-column>
          <el-table-column prop="studentNumber" label="人数" align="content">
          </el-table-column>
          <el-table-column fixed="right" label="操作" align="content">
            <template slot-scope="scope">
              <i style="color: #339dff" @click="Out(scope.row)">打印签到表</i>
            </template>
          </el-table-column>
        </el-table>

        <!-- 分页 -->
        <div class="pagination">
          <el-pagination
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :current-page="query.pageNum"
            :page-sizes="[2, 3, 4, 5]"
            :page-size="query.pageSize"
            prev-text="上一页"
            next-text="下一页"
            layout=" prev, pager, next"
            :total="query.total"
          ></el-pagination>

          <div class="jumper">
            跳到第
            <input type="text" ref="pageNum" :value="query.pageNum" />
            页
          </div>
          <button @click="goPage">确定</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
let newTime = new Date()
import "@/styles/picture.scss";
import { _debounce } from "@/utils/debounce";
import {
  getSignInFormApi,
  printSignInFormApi,
} from "@/api/testManagement/Examination";
export default {
  data() {
    return {
      total: 0,
      examPaper: "",
      multipleSelection: [],
      query: {
        pageNum: 1,
        pageSize: 5,
        total: 0,
      },
      tableData: [],
      examId: "",
      length: "",
      ids: "",
      showTime:""
    };
  },

  mounted() {
    this.getList();
     console.log(Date.now())
  },

  methods: {
    // 手动单选
    itemHandleSelectionChange(selection) {
      //selection为当前所选数据集合，row为当前选中行数据
      console.log(selection.length);
      this.length = selection.length;
    },
    // 全选
    itemHandleSelectionAll(selection) {
      console.log(selection.length);
      this.length = selection.length;
    },
    // 批量打印
    batchPrint() {
      if(this.length == ""){
         this.$message({
          message: '请选择',
          type: 'warning'
        });
        return 
      }
      console.log(this.ids, "idss");
      this.$confirm("确认批量打印吗?", "提示", {
        type: "warning",
      })
        .then(() => {
          printSignInFormApi({ ids: this.ids }).then((res) => {
            console.log(res);
            this.$router.push({
              path: `/TestManagement/Print?ids=` + this.ids,
            });
          });
        })
        .catch(() => {});
    },
    //  获取签到表列表  / 搜索
    getList() {
      getSignInFormApi(this.query).then((res) => {
        console.log(res, "签到表数据123");
        this.tableData = res.rows;
        this.query.total = res.total;
        this.showTime = new Date()-newTime
        console.log(this.showTime)
      });

    },

    // 搜索
    searchInput() {
      getSignInFormApi({ examPaper: this.examPaper }).then((res) => {
        this.tableData = res.rows;
        this.query.total = res.total;
      });
    },

    // 重置
    refreshInput: _debounce(function () {
      this.examPaper = "";
      this.getList()
    }, 200),

    //选中
    handleSelectionChange(val) {
      var arrTostring = [];
      val.forEach((item) => {
        if (arrTostring.indexOf(item.id) === -1) {
          arrTostring.push(item.examId);
        }
      });
      this.ids = arrTostring.toString();
      console.log(this.ids, "ids");
    },

    // 分页
    // 改变每页条数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.query.pageSize = val;
      this.getList();
    },
    //切换页数，执行方法
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.query.pageNum = val;
      this.getList();
    },
    goPage() {
      let { value } = this.$refs.pageNum;
      console.log("1", value);
      this.query.pageNum = Number(value);
      this.getList();
    },

    //跳转
    Out(row) {
      this.ids = row.examId;
      console.log(row.examId);
      this.$router.push({
        path: `/TestManagement/Print?ids=` + this.ids,
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.courseBoxTopSearch {
  ::v-deep .el-input__inner {
    height: 36px;
    line-height: 36px;
  }
  .courseName {
    margin-left: 550px;
  }
}
.action {
  cursor: pointer;

  span {
    font-size: 12px;
    color: #4b93d5;
  }
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: right;
  margin-top: 20px;
  margin-right: 150px;
  .jumper {
    font-size: 14px;
    margin-left: 20px;
    margin-right: 10px;
    display: flex;
    align-items: center;
    input {
      width: 40px;
      height: 26px;
      margin: 0 5px;
      text-align: center;
      border: solid 1px #e6e6e6;
      border-radius: 5px;
      color: #666;
      outline-style: none;
    }
  }
  button {
    height: 28px;
    line-height: 28px;
    border-radius: 5px;
    background-color: #4895db;
    border: solid 1px #4895db;
    color: #fff;
    font-size: 14px;
    padding: 0 8px;
  }
}
.alert {
  width: 100%;
  margin-bottom: 10px;
  border: 1px solid #caedff;
  background: #e6f7ff;
}
</style>